#include <iostream>
#include <vector>
#include <string>

using namespace std;

int removeElement(vector<int> &nums, int val)
{
    int len = nums.size();
    for (int i = 0; i < len; i++)
    {
        if (nums[i] == val)
        {
            while (len >= 1 && nums[len - 1] == val)
                len--;
            if (len - 1 > i)
            {
                nums[i] = nums[--len];
            }
        }
    }
    return len;
}

int main()
{
    vector<int> nums = {1};
    int val = 1;
    cout << removeElement(nums, val) << endl;
    for (int i : nums)
    {
        cout << nums[i] << endl;
    }
    return 0;
}
